home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ABUSESRC.ZIP / AbuseSrc / macabuse / src / zonesel.c < prev   
Encoding:
C/C++ Source or Header  |  1997-05-20  |  2.5 KB  |  106 lines

  1. #include "scroller.hpp"
  2. #include "cache.hpp"
  3. #include "sock.hpp"
  4. #include "jwindow.hpp"
  5. #ifdef __MAC__
  6. #include "atalk.hpp"
  7. #endif
  8.  
  9.  
  10. extern window_manager *eh;
  11.  
  12.  
  13. // used to sort zones into alphabetical order
  14. int str_p_compare(const void *a, const void *b)
  15. {
  16.   return strcmp(  *((char **)a), 
  17.                   *((char **)b));
  18. }
  19.  
  20.  
  21. extern net_protocol *prot;
  22.  
  23. void get_zone()
  24. {
  25.   char *fakes[]={"PC Zone","Apple Zone2","AIX zone"};
  26.   char **strs=fakes;
  27.   int t_zones=3;
  28.   
  29.   //  if (!prot || strcmp(prot->name(),"AppleTalk"))
  30.   // return ;
  31.    
  32.  
  33.   
  34.  
  35.   window_manager *w=eh;
  36.   JCFont *f=w->font();
  37.  
  38.   // notify the user that the computer is not locked (yet)
  39.   char *wait_str="Gathering Zone information, please wait....";
  40.   jwindow *wait_window=w->new_window(xres/2-strlen(wait_str)*f->width()/2-10,
  41.                yres/2-f->height()/2-10,
  42.                -1,-1,
  43.                new info_field(WINDOW_FRAME_LEFT,WINDOW_FRAME_TOP,0,
  44.                wait_str,0));
  45.    w->flush_screen();
  46.    
  47.  
  48. #ifdef __MAC__
  49.   atalk_protocol *ap=(atalk_protocol *)prot;    
  50.   strs=ap->GetZones(t_zones);
  51. #endif  
  52.  
  53.    w->close_window(wait_window);
  54.    
  55.    if (t_zones==0)  // if there are no zones found return back to caller
  56.      return;
  57.  
  58.   qsort(strs,t_zones,sizeof(char *),str_p_compare);           
  59.  
  60.   image *ok_image=cash.img(cash.reg("art/frame.spe","dev_ok",SPEC_IMAGE,1))->copy(),
  61.     *cancel_image=cash.img(cash.reg("art/frame.spe","cancel",SPEC_IMAGE,1))->copy();
  62.  
  63.  
  64.   int show_y=20;
  65.   
  66.    button *cancel_button=new button(WINDOW_FRAME_LEFT,WINDOW_FRAME_TOP+show_y*f->height()+25,
  67.      1,cancel_image,0);
  68.  
  69.   // this is the scroll list which will be inside the window
  70.    //  pick_list(int X, int Y, int ID, int height,
  71.    //        char **List, int num_entries, int start_yoffset, ifield *Next, image *texture=NULL);
  72.  
  73.   pick_list *pick=new pick_list(WINDOW_FRAME_LEFT,
  74.       WINDOW_FRAME_TOP,
  75.       1,
  76.       show_y,
  77.       strs,
  78.       t_zones,
  79.       0,
  80.       cancel_button);
  81.      
  82.   jwindow *zwin=w->new_window(xres/2-f->width()*18-10,yres/2-f->height()*10-18,-1,-1,pick);
  83.  
  84.   event ev;
  85.   int done=0;
  86.   do
  87.   {
  88.     w->flush_screen();
  89.     w->get_event(ev);
  90.     if (ev.type==EV_MESSAGE && ev.message.id==1)
  91.     {
  92.       int pk=pick->get_selection();
  93. #ifdef __MAC__
  94.       if (pk>=0 && pk<t_zones)
  95.         ap->SetZone(strs[pk]);
  96. #endif
  97.       done=1;
  98.     } else if (ev.type==EV_MESSAGE && ev.message.id==2)  // canceled
  99.       done=1;
  100.   } while (!done);
  101.   
  102.   w->close_window(zwin);
  103.   delete cancel_image;
  104.   delete ok_image;
  105. }
  106.